/* 
 * File:   Huffman.h
 * Author: jorge
 *
 * Created on April 23, 2013, 10:12 PM
 */

#ifndef HUFFMAN_H
#define	HUFFMAN_H

#include "HNode.h"
#include "gLinkedList.h"
#include <string.h>

class WordOcurrence
{
public:

    WordOcurrence()
    {
        this->word_ = ' ';
        this->amount_ = 1;
    }

    WordOcurrence(const char word, int amount) : word_(word), amount_(amount)
    {
    }

    const int getAmount()
    {
        return this->amount_;
    }

    void operator++(int amount)
    {
        this->amount_++;
    }

    bool operator==(WordOcurrence ocurrence)
    {
        return ocurrence.word_ == this->word_;
    }

    bool operator>=(WordOcurrence ocurrence)
    {
        return this->amount_ >= ocurrence.amount_;
    }
private:
    char word_;
    int amount_;
};

class Huffman
{
public:
    static void compress(const char* data);
    static void decompress(const char* data);
    static void buildTree(GLinkedList<HNode<WordOcurrence> >& ocurrences);
    static void countOcurrence(const char* str, GLinkedList<HNode<WordOcurrence> > & ocurrences);
};

#endif	/* HUFFMAN_H */

